<?php
class Warehouses_xproducts_model extends CI_Model {

    var $id = '';
    var $name = '';
    var $text = '';
    private $_tabla = 'warehouses';

    function __construct() {
        // Call the Model constructor
        parent::__construct();
    }

    public function getAll()
    {
        $query = $this->db;
        $query = $query->where('status', 1);
        $query = $this->db->get($this->_tabla);
        return $query->result();
    }
    
    public function find($id)
    {
        $query = $this->db->where('id = '.$id)->get($this->_tabla);
        $rs = $query->result();
        return $rs[0];
    }
    
    public function add($data)
    {        
        $this->db->insert($this->_tabla, $data);
        return true;
    }

    public function search($id = null, $name = null, $text = null)
    {
        $query = $this->db;
        if (isset($id) && $id != '') {
            $query = $query->like('id', $id, 'both');
        }
        if (isset($name) && $name != '') {
            $query = $query->like('name', $name, 'both');
        }
        if (isset($text) && $text != '') {
            $query = $query->like('text', $text, 'both');
        }
        $query = $query->where('status', 1);
        $query = $query->get($this->_tabla);
        $rs = $query->result();
        return $rs;
    }

    public function update($id, $data)
    {
        $this->db->where('id', $id);
        $this->db->update($this->_tabla, $data);
        return true;
    }

    public function delete($code)
    {
        $this->db->where('id', $code);
        $this->db->update($this->_tabla, array('status' => 0));
        return true; 
    }
}